home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / lang / genrsp11 / genrsp.c < prev    next >
C/C++ Source or Header  |  1995-03-31  |  7KB  |  157 lines

  1. //-------------------------------------------------------------------------
  2. // GENRSP v1.0 Version 1.0
  3. // Copyright (c) 1995 Eric Coolman, Simple Minded Software
  4. // Contact via internet at: eric.coolman@mcc.uti.com
  5. //-------------------------------------------------------------------------
  6. // This is a simple replacement for Borland's MAKERSP.EXE. I find this
  7. // utility more useful and functional than Borland's version.  It still
  8. // handles printf() style string formatting, as well as fixing a few bugs
  9. // found in MAKERSP ie. printing the tailing ampersand (&), requiring
  10. // manual editing afterwards. I found MAKERSP cumbersome in which it
  11. // requires an input file to start out with as well.  This is where GENRSP
  12. // differs from MAKERSP... rather than taking an input file, you give it
  13. // wildcard specs, and on top of that, you can stack filespecs by
  14. // separating them with a semicolon, giving full paths to the filespecs
  15. // (the paths will be used in the response file). Type "GENRSP.EXE" by
  16. // itself at the dos prompt for example syntax.
  17. //-------------------------------------------------------------------------
  18. // Although this code is copyrighted, permission is granted for unlimited
  19. // and use, modification, and distribution, as long as the original author
  20. // (Eric Coolman, Simple Minded Software) is creditted as such (in
  21. // documentation), and the original copyright notice (above) remains intact.
  22. //
  23. // Any usage of this code and/or utility is at own risk!  Sorry for the
  24. // ugly code, but I didn't feel like spending any time on it.
  25. // Command-line compile with: BCC -mt -lt -O1 genrsp.c
  26. //-------------------------------------------------------------------------
  27. // Revisions:
  28. // March 30, 1995 - v1.0 - Initial release.
  29. // March 31, 1995 - v1.1 - Ooops.  See v1.1 notes below.
  30. //-------------------------------------------------------------------------
  31. #include <string.h>     // various string manip funcs.
  32. #include <stdio.h>      // ...printf() functions
  33. #include <stdlib.h>     // atoi(), _fullpath()
  34. #include <dir.h>        // struct ffblk, findfirst/next(), fnsplit/merge()
  35.  
  36. char helptext[] =
  37. "\nGENRSP  Version 1.1  Copyright (c) 1995 Simple Minded Software"
  38. "\nGenerates a response file for use with Borland's TLIB."
  39. "\n\nGENRSP \"printf format string\" [[drive:][path]filemask[ ...]]"
  40. "\n\n\"printf format string\"      - format specifier string (as in printf())"
  41. "\n[drive:][path]filemask(s)   - specifies files to be LIB'ed"
  42. "\nExample command:            - GENRSP \"\\n-+%%%%s &\" *.obj >> objlist.rsp"
  43. "\n                            - GENRSP \"\\n-+%%%%s &\" *.c;*.cpp >> objlist.rsp";
  44.  
  45. char *AbsPath(char *inpath, char *infile, char *abspath)
  46. {
  47.     char drive[MAXDRIVE], dir[MAXDIR], relative[MAXPATH];
  48.     fnsplit(inpath, drive, dir, NULL, NULL);    // remove any filespecs
  49.     fnmerge(relative, drive, dir, NULL, NULL);  // reconstruct dir only
  50.     strcat(relative, infile);                   // concat curfile
  51.     return _fullpath(abspath, relative, MAXPATH); // normalize the path
  52. }
  53.  
  54. // Input :  See above.
  55. // Return:  0 = No Error, 1 = No files found, 2 = Error in command line
  56. int main(int argc, char *argv[])
  57. {
  58.     char buffer[MAXPATH], formatted[MAXPATH], abs[MAXPATH], *token, *ext;
  59.     int i, rc = 1, done = 0;
  60.     struct ffblk ffblk;
  61. //-- v1.1 : Was only checking asking for 1 input parm.  Now make sure there
  62. //        : are at least 2.
  63.     if (argc < 3)
  64.     {
  65.         printf(helptext);
  66.         return 2;
  67.     }
  68.     memset(buffer, 0, MAXPATH);
  69.     memset(abs, 0, MAXPATH);
  70.     for (i = 1; i < argc-2; i++) // concatinate all parameters except last
  71.         strcat(strcat(buffer, argv[i]), " ");
  72.     strcat(buffer, argv[i]);     // avoid concatinating space to end
  73.     // replace control code strings with actual control codes
  74.     while ((token = strchr(buffer, '\\')) != NULL)
  75.     {
  76.         *token = ' ';                  // kill the slash
  77.         switch (*(token + 1))
  78.         {
  79.              case 'n':                 // newline (linefeed)
  80.                  *(token + 1) = '\n';
  81.                  break;
  82.              case 'r':                 // carriage return
  83.                  *(token + 1) = '\r';
  84.                  break;
  85.              case 't':                 // horizontal tab
  86.                  *(token + 1) = '\t';
  87.                  break;
  88.              // The rest useless, but just in case:
  89.              case 'v':                 // vertical tab
  90.                  *(token + 1) = '\v';
  91.                  break;
  92.              case 'b':                 // backspace
  93.                  *(token + 1) = '\b';
  94.                  break;
  95.              case 'a':                 // audible bell
  96.                  *(token + 1) = '\a';
  97.                  break;
  98.              case 'f':                 // form feed
  99.                  *(token + 1) = '\f';
  100.                  break;
  101.              case '\\':                // backslash
  102.                  *(token + 1) = '\\';
  103.                  break;
  104.              case '\'':                // single quote (apostrophe)
  105.                  *(token + 1) = '\'';
  106.                  break;
  107.              case '\"':                // double quote
  108.                  *(token + 1) = '\"';
  109.                  break;
  110.              case 'x':                 // hex string
  111.                  i = atoi(token + 2);
  112.                  *(token + 1) = (((i / 10) << 4) + (i % 10));
  113.                  *(token + 2) = ' ';
  114.                  if (i > 9)
  115.                      *(token + 3) = ' ';
  116.                  break;
  117.         }
  118.     }
  119.     token = strtok(argv[argc-1], ";");  // start unstacking filelists
  120.  
  121.     do
  122.     {
  123.         done = findfirst(token, &ffblk, 0);
  124.         if (! done)
  125.         {
  126.             rc = 0;  // found a match, so we'll have an .RSP file
  127.             while (! done)
  128.             {
  129.                 if (*abs) // start printing after second match
  130.                 {   // reformat so it doesn't mess up on redirection
  131.                     sprintf(formatted, buffer, abs);
  132.                     printf(strupr(formatted));
  133.                 }
  134.                 AbsPath(token, ffblk.ff_name, abs);
  135. //-- v1.1 : Wouldn't parse files with no extension properly.  It will now.
  136.                 if ((ext = strrchr(abs, '.')) != NULL) // has extension
  137.                     *ext = 0;                          // remove extension
  138.                 strcat(abs, ".OBJ");                   // change to .obj
  139.                 done = findnext(&ffblk);
  140.             }
  141.         }
  142. //-- v1.1 : Remmed this out so it doesn't get redirected to output file,
  143. //        : in case more found entries (stacked wildcards) follow.
  144. //        else
  145. //            printf("\nPattern \"%s\" not found.", token);
  146.     } while ((token = strtok(NULL, ";")) != NULL);
  147.  
  148.     if (*abs) // if we found any matches at all, we'll have one left over
  149.     {
  150.         if (strchr(buffer, '&'))
  151.             *strrchr(buffer, '&') = ' ';
  152.         sprintf(formatted, buffer, abs);
  153.         printf(formatted);
  154.     }
  155.     return rc;
  156. }
  157.